//
//  DelCollectViewModel.swift
//  Pods
//
//  Created by eme on 2017/3/30.
//
//

import RxSwift
import SwiftyJSON
import NetWorkCore
import ModelProtocol
import RickonCore

class DelCollectViewModel{
    
    let setBrandCollect = PublishSubject<String>()
    
    let backDate = Variable<[CollectBrandModel]>([])
    
    let disposeBag = DisposeBag()
    
    let error = PublishSubject<MikerError>()
    
    let refreshing = Variable(false)
    
    init (){
        
        let request = setBrandCollect.map{ cid in
            
            return MineApi.deleteBrandCollect(cid: cid,page: 0,length: AppConfig.pageSize)
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForArray(CollectBrandModel.self).shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            
            switch result{
                
            case .success(let data):
                
                self.backDate.value = data
                
            case.failure(let error):
                
                self.error.onNext(error)
                
            }
            
        }).addDisposableTo(disposeBag)
    }
    
}
